import 'dart:typed_data';
import 'package:encrypt/encrypt.dart';

// AES工具类
class AesUtil {
  // ECB加密
  static encryptEcbNoPadding(Uint8List content, Uint8List pwd) {
    final encrypter = Encrypter(AES(Key(Uint8List.fromList(pwd.toList())),
        mode: AESMode.ecb, padding: null));
    return Uint8List.fromList(
        encrypter.encryptBytes(content, iv: IV.fromLength(16)).bytes);
  }

  // ECB解密
  static decryptEcbNoPadding(Uint8List content, Uint8List pwd) {
    final encrypter = Encrypter(AES(Key(Uint8List.fromList(pwd.toList())),
        mode: AESMode.ecb, padding: null));
    return Uint8List.fromList(encrypter.decryptBytes(
        Encrypted(Uint8List.fromList(content.toList())),
        iv: IV.fromLength(16)));
  }
}
